<?php
/**
 * Created by JetBrains PhpStorm.
 * User: миха
 * Date: 19.07.13
 * Time: 20:02
 * To change this template use File | Settings | File Templates.
 */
class Model_Category extends Model_Default
{
    function __construct()
    {

    }

    function getCategoryData($categoryId, $OrderBy)
    {
        $categoryId = (int)$categoryId;
        $limitBegin =(int) $OrderBy["lB"];
        $limitCount =(int) $OrderBy["lC"];
        $ordreNamePrice = (int) $OrderBy["oNP"];

        switch($ordreNamePrice)
        {
            case Model_Model::$orderCategoryPrice:
                $oSubCategory = ("Price");
                break;
            case Model_Model::$orderCategoryName:
                $oSubCategory = ("Name");
                break;
            default:
                break;
        }

        $query_categoria = <<<SQL
                            SELECT
                              t.Name, t.id, t.Image, t.Price, t.mini_Data, cd.cat, pd.podcat
                            FROM
                              Tovar_cat AS tc
                            RIGHT JOIN
                              Tovar AS t
                            ON
                              tc.id_tovar = t.Id
                            RIGHT JOIN
                              cat_data AS cd
                            ON
                              tc.cat = cd.Id
                            RIGHT JOIN
                              podcat_data AS pd
                            ON
                              tc.podcat = pd.Id
                            WHERE
                              tc.cat =$categoryId
                              AND
                              t.in_moderate = 0
                              AND
                              t.is_hide = 0
                            ORDER BY
                              $oSubCategory
                            LIMIT
                              $limitBegin, $limitCount
SQL;

        $db = $this->dbh();
        $stmt = $db->query($query_categoria);
        $result = $stmt->fetchALL(PDO::FETCH_ASSOC);
        return $result;
    }
}